import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, ManyToMany } from 'typeorm';
import { Article } from './article.entity';

@Entity()
export class Tag {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ unique: true })
  name: string;

  @Column({ default: 0 })
  usageCount: number;

  @Column({ type: 'int', default: 1 }) // 0: 禁用, 1: 启用
  isActive: number;

  @CreateDateColumn()
  createdAt: Date;

  @UpdateDateColumn()
  updatedAt: Date;

  // 文章与标签的多对多关系 
  @ManyToMany(() => Article, article => article.tags)
  articles: Article[];
}